package xin.printk.android.view.adapter;

import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import xin.printk.android.utils.LogUtils;

public class CycleViewPagerAdapter<T extends View> extends PagerAdapter {

    private List<T> src;

    public CycleViewPagerAdapter(List<T> src) {
        this.src = src;
    }

    @Override
    public int getCount() {
        return src == null ? 0 : src.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        LogUtils.d("add view position is " + position);
        container.addView(src.get(position));
        return src.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        LogUtils.d("destroyItem position is " + position);
        container.removeView(src.get(position));
    }
}
